package com;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;

import com.rabbitmq.service.RabbitMqService;

/**
 * Hello world!
 *
 */
@SpringBootApplication
public class RabbitMqProducerApplication 
{
    public static void main( String[] args )
    {
     ApplicationContext ac =  SpringApplication.run(RabbitMqProducerApplication.class, args);
     RabbitMqService rabbitMqService = ac.getBean(RabbitMqService.class);
     String[] topic = new String[] {"a.orange","b.orange.b","b.orange.rabbit","b.orange.rabbit.b","lazy.orange.rabbit","lazy"};
     for (int i = 0; i < 1000; i++) {
		  try {
			Thread.sleep(1000);
		  } catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		  }
	  	/*工作队列模式*/
	  	rabbitMqService.sendMessage("工作队列模式："+i);
		/*发布/订阅者模式*/
		rabbitMqService.sendMessage2( "发布/订阅者模式："+i);
		/*路由模式*/
		if(Math.random()*10>5) {
			rabbitMqService.sendRoutingMessage("error","日志级别：error "+i);
		}else {
			rabbitMqService.sendRoutingMessage("info","日志级别：info "+i);
		}
		/*topic模式（主题模式）*/
		int length = topic.length;
		
		int index = i%length;
		rabbitMqService.sendTopicMessage(topic[index],"日志主题模式： "+topic[index]);
	}
    }
}
